package com.jilefojing.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import com.jilefojing.beans.pojos.DBuddhism;
import com.jilefojing.beans.query.DBuddhismQuery;
import com.jilefojing.beans.vo.Pagination;
import com.jilefojing.dao.IDBuddhismDao;
import com.jilefojing.dao.base.impl.BaseDao;
import com.jilefojing.dao.mapper.IDBuddhismMapper;
import com.jilefojing.util.Detect;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年10月06日 23时59分44秒
 */
@Repository
public class DBuddhismDao extends BaseDao<DBuddhism> implements IDBuddhismDao {
	@Autowired
	private IDBuddhismMapper dBuddhismMapper;

	@Override
	public Pagination<DBuddhism> getPagination(DBuddhismQuery dBuddhismQuery,
			Pagination<DBuddhism> pagination) {
		Example example = new Example(DBuddhism.class);
		Criteria criteria = example.createCriteria();
		if (Detect.notEmpty(dBuddhismQuery.getIds())) {
			criteria.andIn(DBuddhism.FIELD_ID, dBuddhismQuery.getIds());
		}

		if (Detect.notEmpty(dBuddhismQuery.getName())) {
			criteria.andEqualTo(DBuddhism.FIELD_NAME, dBuddhismQuery.getName());
		}

		if (Detect.notEmpty(dBuddhismQuery.getLike_name())) {
			criteria.andLike(DBuddhism.FIELD_NAME,
					"%" + dBuddhismQuery.getLike_name() + "%");
		}

		if (dBuddhismQuery.getEqualCreateTime() != null) {
			criteria.andEqualTo(DBuddhism.FIELD_CREATETIME,
					dBuddhismQuery.getEqualCreateTime());
		}

		if (dBuddhismQuery.getEqualAndBeforCreateTime() != null) {
			criteria.andGreaterThanOrEqualTo(DBuddhism.FIELD_CREATETIME,
					dBuddhismQuery.getEqualAndBeforCreateTime());
		}

		if (dBuddhismQuery.getEqualAndAfterCreateTime() != null) {
			criteria.andLessThanOrEqualTo(DBuddhism.FIELD_CREATETIME,
					dBuddhismQuery.getEqualAndAfterCreateTime());
		}

		if (dBuddhismQuery.getBeforCreateTime() != null) {
			criteria.andGreaterThan(DBuddhism.FIELD_CREATETIME,
					dBuddhismQuery.getBeforCreateTime());
		}

		if (dBuddhismQuery.getAfterCreateTime() != null) {
			criteria.andLessThan(DBuddhism.FIELD_CREATETIME,
					dBuddhismQuery.getAfterCreateTime());
		}
		if (Detect.notEmpty(pagination.getOrders())) {
			example.setOrderByClause(pagination.getOrdersToStr());
		}
		return super.getPagination(pagination, example);
	}

	@Override
	public List<DBuddhism> getListByIds(List<Long> ids) {
		Example example = new Example(DBuddhism.class);
		example.createCriteria().andIn(DBuddhism.FIELD_ID, ids);
		return super.getListByExample(example);
	}
}
